package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import org.testng.annotations.Test;

import com.example.fw.Folders;


public class TestFolderCreation extends TestBase {

	@Test
	public void testFolderCreation(){		
		String folder = "new Folder";		
		Folders oldFolders = app.getFolderHelper().getFolders();		
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));		
		Folders newFilders = app.getFolderHelper().getFolders();		
		assertThat(newFilders, equalTo(oldFolders.whithAdded(folder)));
	}
	
	@Test
	public void testVariousFoldersCreation(){		
		String folder1 = "new Folder1";
		String folder2 = "new Folder2";
		
		Folders oldFolders = app.getFolderHelper().getFolders();
		
		assertThat(app.getFolderHelper().createFolder(folder1), is(nullValue()));			
		Folders newFilders = app.getFolderHelper().getFolders();		
		assertThat(newFilders, equalTo(oldFolders.whithAdded(folder1)));
		
		assertThat(app.getFolderHelper().createFolder(folder2), is(nullValue()));
		Folders newFilders2 = app.getFolderHelper().getFolders();		
		assertThat(newFilders2, equalTo(newFilders.whithAdded(folder2)));
	}
	
	
	@Test
	public void testFoldersWithSameNameCreation(){		
		String folder = "new Folder3";
		Folders oldFolders = app.getFolderHelper().getFolders();
		
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));	
	
		Folders newFolders = app.getFolderHelper().getFolders();		
		assertThat(newFolders, equalTo(oldFolders.whithAdded(folder)));
		
		assertThat(app.getFolderHelper().createFolder(folder), containsString("Duplicated folder name") );	
		
		Folders newFolders2 = app.getFolderHelper().getFolders();		
		assertThat(newFolders2, equalTo(newFolders));
	}
}
